<?php

namespace App\Controller\ApiCloud;

use App\Base\BaseConfig;
use App\Base\BaseController;
use App\Base\BaseModel;
//use BaseExt\JPush;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;


/**
 * @route("/ApiCloud")
 */
class ApiCloudController extends BaseController
{
    public function initData()
    {
        $env = $this->getParameter('env');
        if ( $env == "dev") {
//            $env = "dev";
            $data["rnd"] = "?rnd=".date("YmdHis");
//            $data["rnd"] = "?rnd=".(floor(time()/30));
//            $data["rnd"] = "?v=1.09";
//            $data["rnd"] = "?v=1.01";
//            $data["rnd"] = "?rnd=".date("YmdH");
            $data["asset"] = BaseConfig::__BASE_URL__."/ApiCloud";
            $data["root"] = "/ApiCloud";
        } else {
//            $env = "dev";
            $data["rnd"] = "?v=1.61";
//            $data["rnd"] = "?rnd=".date("YmdH");
            $data["asset"] = BaseConfig::__BASE_URL__."/ApiCloud";
            $data["root"] = "/ApiCloud";
        }
        $data["env"] = $env;
        $data["defaultPic"] = $data["asset"]."/assets/default.png";
//        $data["ripple"] = "<mu-ripple></mu-ripple>";
        return $data;
    }

    /**
     * @route("/Page/{ClientName}/{PageName}.html",name="ApiCloudCommentPageNew")
     */
    public function ApiCloudCommentPageNew($ClientName,$PageName){
        $data = $this->initData();
        $data["PageName"] = "$PageName";
        $data["Client"] = $ClientName;
        $Client = ucfirst($ClientName);
        try {
            return $this->render("ApiCloud/$Client/$PageName.php.twig",$data);
        } catch (\Exception $e) {
            die("<h2 style='text-align: center;'>技术小哥哥<br>正在努力……<br>努力赚加班费……<br>(￥ω￥)</h2>".$e->getMessage());
        }
    }

    /**
     * @route("/ApiCloudGenerateLocalFile",name="ApiCloudGenerateLocalFile")
     */
    public function ApiCloudGenerateLocalFile()
    {// /ApiCloud/ApiCloudGenerateLocalFile
        $UserFiles = "about.php.twig
articles.php.twig
articlesInfo.php.twig
categorySelect.php.twig
citySelector.php.twig
classInfo.php.twig
coinShop.php.twig
fillPhone.php.twig
fuli.php.twig
help.php.twig
index.php.twig
liveBuy.php.twig
liveInfo.php.twig
login.php.twig
main.php.twig
map.php.twig
mapPicker.php.twig
mapTop.php.twig
match.php.twig
myAddress.php.twig
myAddressAdd.php.twig
myAddressSelect.php.twig
myAuth.php.twig
myContact.php.twig
myContactAdd.php.twig
myContactSelect.php.twig
myService.php.twig
myShopOrder.php.twig
myShopOrderAppeal.php.twig
myShopOrderInfo.php.twig
myTask.php.twig
myTaskInfo.php.twig
myTaskPayHire.php.twig
news.php.twig
newService.php.twig
newsInfo.php.twig
newTask.php.twig
newTaskStep.php.twig
page.php.twig
play.php.twig
pub.php.twig
question.php.twig
reg.php.twig
search.php.twig
serviceCreateOrder.php.twig
services.php.twig
servicesInfo.php.twig
servicesPay.php.twig
servicesRecomment.php.twig
servicesSelect.php.twig
setting.php.twig
settingSafe.php.twig
shopAuth.php.twig
shopCat.php.twig
shopHome.php.twig
shopIndex.php.twig
shopInfo.php.twig
shopInsureMoney.php.twig
shopInsurePay.php.twig
shopTag.php.twig
suggest.php.twig
task.php.twig
taskInfo.php.twig
taskVote.php.twig
user.php.twig
userAddress.php.twig
userCash.php.twig
userCertificate.php.twig
userCharge.php.twig
userCoin.php.twig
userDown.php.twig
userInfo.php.twig
userInvite.php.twig
userInviteSons.php.twig
userLike.php.twig
userMoney.php.twig
userMoneyExchange.php.twig
userMoneyFenhong.php.twig
userMoneyLog.php.twig
userMoneyXuni.php.twig
userNickName.php.twig
userOrder.php.twig
userSetGrade.php.twig
userVip.php.twig";
        $pages = mb_split("\n",$UserFiles);
        $data["rnd"] = "?rnd=".date("YmdHis");
        $data["asset"] = BaseConfig::__BASE_URL__."/ApiCloud";
        $data["root"] = BaseConfig::__BASE_URL__."/ApiCloud";
        $data["root"] = "ApiCloud";
        $data["Client"] = "user";
        $data["env"] = "prod";
        foreach ($pages as $fileName) {
            $fileName = trim($fileName);
            $PageName =  substr($fileName,0,-9);
            $data["PageName"] = "$PageName";
            $HtmlName = $PageName.".html";
            $client = ucfirst($data["Client"]);
            $html = $this->renderView("ApiCloud/$client/$fileName",$data);
            //检查目录是否存在
            if (!is_dir("./tmp/".$data["Client"] )) {mkdir("./tmp/".$data["Client"] );}
            if (!file_exists("./tmp/".$data["Client"] ."/".$HtmlName)) {}
            file_put_contents("./tmp/".$data["Client"] ."/".$HtmlName,$html);
            var_dump($HtmlName);
        }
    }

}
